/*LICENSE_BEGIN
 * ******************************************************************
 * Copyright 2006 by the Dainamite Robocup-Team at the
 * DAI-Labor, TU-Berlin (www.dai-labor.de)
 * 
 * Members of Dainamite are:
 * Holger Endert
 * Robert Wetzker
 * Thomas Karbe
 * Axel Heßler
 * Philippe Bütter
 * Felix Brossmann
 * 
 * Licensed under the GNU GPL (General Public License) Free Software 
 * License, Version 2. You may use this file only in compliance with 
 * the License. You may obtain a copy of the License at:
 * 
 * http://www.fsf.org/licensing/licenses/gpl.txt
 * ******************************************************************
LICENSE_END*/
package robocup.component.actionfactories;

import robocup.component.WorldModel;
import robocup.component.actions.Action;
import robocup.component.actions.PointToAction;
import robocup.component.geometry.Vektor;
import robocup.component.worldobjects.Player;
import robocup.component.worldobjects.Player.RELATIVE;

/**
 * A factory for creating pointTo actions.  
 */
public class PointToActionFactory {

	/**
	 * Vektor object for calculating the target to point at!
	 */
	public static final Vektor pointVektor = new Vektor();

	/**
	 * a dummy-object
	 */
	public static final Player selfDummy = Player.getDummyInstance();

	/**
	 * This method calculates a pointToAction to an absolute target, whereas the
	 * point of view is the player.
	 * 
	 * @param world -
	 *            the current world-model
	 * @param pointTo -
	 *            the target vektor
	 * @param mainAction the main action
	 * @return the pointTo Action, targeting from <self> to <pointTo>
	 */
	public static PointToAction pointToPoisitionAction(WorldModel world,
			Vektor pointTo, Action mainAction) {
		selfDummy.copy(world.getSelfRef());
		selfDummy.predictThisAfterAction(mainAction);
		double angleTo = selfDummy.getAngleRel(pointTo, RELATIVE.TO_HEAD);
		double distTo = selfDummy.getDistance(pointTo);

		return new PointToAction(distTo, angleTo);
	}

}
